using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Templates_Article_LatestIssue : Acms.AcmsControls.TemplateUserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private string latestIssueUrl;
    public string LatestIssueUrl
    {
        get 
        {
            if (string.IsNullOrEmpty(latestIssueUrl))
            {
                latestIssueUrl = string.Concat(AcmsContext.CurrentPost.ParentUrl, AcmsContext.CurrentPost.ParentUrl.Contains("?") ? "&" : "?", GetQuerystring());
            }
            return latestIssueUrl; 
        }
    }

    private string GetQuerystring()
    {
        //iterate up until post found then use the id in querystyring
        IDataItemContainer container = null;
        Control current = this;
        while ((container == null || !(container.DataItem is Acms.Bll.Topic)) && current != null && current.NamingContainer != null)
        {
            current = current.NamingContainer;
            container = current as IDataItemContainer;
        }
        if (container != null)
        {
            return string.Format("SelectedTopic={0}", ((Acms.Bll.Topic)container.DataItem).Id);
        }
        else
        {
            return null;
        }
    }
	
}
